//
//  StatusOriginalView.swift
//  SinaWeiBo
//
//  Created by tuyue on 16/3/15.
//  Copyright © 2016年 xueyang.co.ltd. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage

/**设置全局变量*/
let StatusCellMargin:CGFloat = 10
class StatusOriginalView: UIView {
    
    var status: Status? {
        didSet{
            iconView.sd_setImageWithURL(status?.user?.headImageURL)
            nameLabel.text = status?.user?.name
            mbrank_image.image = status?.user?.mbrank_image
            verified_image.image = status?.user?.verified_type_image
            sourceLabel.text = status?.source
            timeLabel.text = status?.created_at
            contentLabel.text = status?.text
            pictureView.imageURLs = status?.imageURLs
            
        }
        
    }
    
    //MARK: - 初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 设置UI
    func setupUI(){
        addSubview(iconView)
        addSubview(mbrank_image)
        addSubview(verified_image)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contentLabel)
        addSubview(pictureView)
        
        //MARK: - 给子控件添加约束
        //iconImageView的约束
        iconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.top.equalTo(self.snp_top).offset(StatusCellMargin)
            make.size.equalTo(CGSize(width: 36, height: 36))
        }
        //设置iconView显示为圆角
        iconView.layer.cornerRadius = 18
        //确定切边
        iconView.layer.masksToBounds = true
        
        //mbrank_image的约束
        mbrank_image.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLabel.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
        }
        
        //verified_image的约束
        verified_image.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(iconView.snp_right)
            make.bottom.equalTo(iconView.snp_bottom)
        }
        
        //nameLabel的约束
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_top)
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
        }
        
        //timeLabel的约束
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconView.snp_bottom)
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
        }
        
        //sourceLabel的约束
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(timeLabel.snp_bottom)
            make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
        }
        
        //contentLabel的约束
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(iconView.snp_left)
            make.right.equalTo(self.snp_right).offset(-StatusCellMargin)

        }
        //MARK: - 添加原创微博中图片的约束
        /**添加原创微博中图片的约束*/
        pictureView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentLabel.snp_left)
            
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
//            make.size.equalTo(CGSize(width: 100, height: 100))
        }
//        pictureView.backgroundColor = UIColor.yellowColor()
        
        /**添加原创微博底部的约束*/
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
        }
        
        
        
    }
    
    
    
    //MARK: - 懒加载属性
    /**用户头像*/
    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    /**认证类型*/
    private lazy var mbrank_image: UIImageView = UIImageView(image: UIImage(named: "conmon_icon_menbership"))
    /**会员等级*/
    private lazy var verified_image: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    /**昵称label*/
    private lazy var nameLabel:UILabel = UIFactory.factoryLable("小花", fontSize: 15, textColor: UIColor.darkGrayColor())
    /**时间label*/
    private lazy var timeLabel:UILabel = UIFactory.factoryLable("22:22", fontSize: 11, textColor: UIColor.darkGrayColor())
    /**来源label*/
    private lazy var sourceLabel:UILabel = UIFactory.factoryLable("iphone7", fontSize: 11, textColor: UIColor.darkGrayColor())
    /**内容label*/
    private lazy var contentLabel:UILabel = UIFactory.factoryLable("都他妈给我滚犊子", fontSize: 14, textColor: UIColor.darkGrayColor(), textAligment: .Left)
    
    //MARK: - 导入pictureView
    /**懒加载pictureView，将图片所在的collectView嵌套进OriginalView*/
    private lazy var pictureView: StatusPictureView = StatusPictureView()
    
}
